package cn.ittest.controller;
/*
* 控制层
* */

import cn.ittest.dao.StudentDao;
import cn.ittest.domain.Student;
import cn.ittest.service.StudentService;
import cn.ittest.service.impl.StudentServiceImpl;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Date;

public class StudentController {
    //查询所有操作
    private StudentService service = new StudentServiceImpl();
    @Test
    //查询所有
   public void findAll() {
       ArrayList<Student> list = service.findAll();
       for (Student stu : list) {
           System.out.println(stu);
       }
       System.out.println("-------------------------");
   }
    @Test
    //有条件查询
    public  void findById() {
        Student stu = service.findById(3);
        System.out.println(stu);
    }
    @Test
    //新增数据
    public void insert() {
        Student stu = new Student(5,"周七",25,new Date());
        int i = service.insert(stu);
        System.out.println(i);

    }
    @Test
    //删除数据
    public void delete() {
        Student stu = new Student();
        stu.setSid(2);
        int count = service.delete(stu);
        System.out.println(count);
    }
    @Test
    //修改数据
    public void update() {
        Student stu = new Student();
        stu.setSid(4);
        stu.setName("刘伟");
        stu.setAge(28);
        int update = service.update(stu);
        if(update != 0) {
            System.out.println("修改成功！！！");
        }
    }

}
